<template>
  <div class="row">
    <Floating class="Floating"></Floating>
    <el-main class="ctxt" v-for="(item, index) in forumData" :key="index">
      <el-container>
        <el-header  class="cl-top">
          <i v-if="item.good">
            <img
              class="typeImg"
              draggable="false"
              src="https://cdn.hterobot.com/vue/public/forum/jian.png"
            >
          </i>
          <i v-if="item.lock">
            <img
              class="typeImg"
              draggable="false"
              src="https://cdn.hterobot.com/vue/public/forum/jian.png"
            >
          </i>
          <i v-if="item.top">
            <img
              class="typeImg"
              draggable="false"
              src="https://cdn.hterobot.com/vue/public/forum/re.png"
            >
          </i>
          <h4>
            <router-link class="route" :to="{name: 'detail', params:{id: item.ID}}">{{item.title}}</router-link>
          </h4>
        </el-header>
        <el-main class="text">{{item.txt}}</el-main>
        <el-footer height="30px" class="footer row text-center">
          <router-link :to="{name: 'user', params:{uid: item.uid}}" class="col-4\ text-left" >
            <img
              class="authorImg"
              draggable="false"
              :src="item.headimg?item.headimg:'/public/static/imgs/forum/touxiang.png'"
            >
            <span>{{item.username}}</span>
          </router-link>
          <div class="col">
            <div class="row">
              <div class="col-4\">
                <span v-text="times(item.createtime)"></span> 天前
              </div>
              <div class="col">
                <i class="icon-xinxi icon iconfont"></i>
                {{ item.reply_count }}
              </div>
              <div class="col-4\">
                <i class="el-icon-view"></i>
                {{ item.click_count }}
              </div>
              <div class="col">
                <i class="icon-xinaixin- icon iconfont text-success"></i>
                {{ item.collect_count }}
              </div>
            </div>
          </div>
        </el-footer>
      </el-container>
    </el-main>
    <br>
    <br>
    <br>
    <el-pagination
      v-show="gettopiccount>25"
      @current-change="handleCurrentChange"
      small
      :page-size="25"
      layout="prev, pager, next"
      :total="gettopiccount"
    ></el-pagination>
  </div>
</template>

<script>
import Floating from "./Floating.vue"
import { asyncgettopic } from "../../../plugins/api.js";
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      forumData: []
    };
  },
  async created() {
    this.start();
  },
  computed: mapGetters(["gettopiccount","getuser"]),
  watch: {
    $route() {
      this.start();
    }
  },
  components:{
    Floating
  },
  mounted() {},
  methods: {
    handleCurrentChange(v) {
      this.$router.push({
        name: "forun",
        query: {
          limit: 25,
          offset: 25 * (v - 1)
        }
      });
    },
    async start() {
      let x = this.$route.query.id;
      let limit = this.$route.query.limit;
      let offset = this.$route.query.offset;
      let data = {
        offset,
        limit
      };
      switch (x) {
        case 1:
          data.order = "createtime";
          console.log(data.order)
          break;
        case 2:
          data.order = "collect_count";

          break;
        case 3:
          data.order = "good";

          break;
      }
      this.forumData = await asyncgettopic(data);
    },
    times(time) {
      return Math.ceil(
        (Date.parse(new Date()) - Date.parse(new Date(time))) /
          1000 /
          60 /
          60 /
          24
      );
    }
  }
};
</script>

<style lang='scss' scoped>
@media (min-width: 1200px) {
  .Floating {
    display: none;
  }
}
.Floating {
        position: fixed;
    bottom: 11rem;
    right: 0.5rem;
    z-index: 9;
    opacity: 0.85;
  }
.text-success{
  color:red !important; 
}
.cl-top {
  height: 24px;
  line-height: 24px;
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

.authorImg {
  margin-right: 8px;
  border-radius: 20px;
  width: 20px;
  height: 20px;
}

.text {
  height: 100px;
  overflow: hidden;
  line-height: 25px;
}
.ctxt {
  width: 100%;
  background-color: #ffffff;
  border-bottom: 1px solid #dfdfdf;
}
.footer {
  line-height: 30px;
}
.route:hover {
  color: #000000;
}
</style>